I can't get that `bus error` to stop sucking.
Posted
by Koning Baard XIV
on Stack Overflow
See other posts from Stack Overflow
or by Koning Baard XIV
Published on 2010-04-25T13:14:14Z
Indexed on
2010/04/25
13:23 UTC
Read the original article
Hit count: 197
I have this a class called PPString:
PPString.h
#ifndef __CPP_PPString
#define __CPP_PPString
#include "PPObject.h"
class PPString : public PPObject {
char *stringValue[];
public:
char *pointerToCharString();
void setCharString(char *charString[]);
void setCharString(const char charString[]);
};
#endif
PPString.cpp
#include "PPString.h"
char *PPString::pointerToCharString() {
return *stringValue;
}
void PPString::setCharString(char *charString[]) {
*stringValue = *charString;
}
void PPString::setCharString(const char charString[]) {
*stringValue = (char *)charString;
}
I'm trying to set the stringValue
using std::cin
:
main.cpp
PPString myString;
myString.setCharString("LOLZ");
std::cout << myString.pointerToCharString() << std::endl;
char *aa[1000];
std::cin >> *aa;
myString.setCharString(aa);
std::cout << myString.pointerToCharString() << std::endl;
The first one, which uses a const char
works, but the second one, with a char
doesn't, and I get this output:
copy and paste from STDOUT
LOLZ
im entering a string now...
Bus error
where the second line is what I entered, followed by pressing the return
key.
Can anyone help me fixing this? Thanks...
© Stack Overflow or respective owner